<template>
  <div style="text-align: center">
    <h1 style="color: #8c939d">上传的excel必须是本站下载的，符合本站要求的</h1>
    <el-upload
      class="avatar-uploader"
      action="/wapsjson/returncvs.json"
      :show-file-list="true"
      :on-success="handleAvatarSuccess"
      :before-upload="beforeAvatarUpload">
      <img v-if="imageUrl" :src="imageUrl" class="avatar">
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
  </div>
</template>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  background-color: rgba(0,0,0,.1)
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
  import {ajax} from '../../data/wap-service'
  export default {
    data() {
      return {
        imageUrl: ''
      };
    },
    mixins:[ajax],
    methods: {
      handleAvatarSuccess(res, file) {
        if (res.success) {
          this.success("上传成功！");
        }else{
          this.error("失败："+res.msg);
        }
      },
      beforeAvatarUpload(file) {
        const isLt2M = file.size / 1024 / 1024 < 10;

        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 10MB!');
        }
        return isLt2M;
      }
    }
  }
</script>
